package com.roc.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.roc.dao.ISQLBaseDao;
import com.roc.pojo.ProfitShare;
import com.roc.service.IProfitShareService;
import com.roc.service.ServiceException;
import com.roc.util.Constance;

/**
 * 
 * 分润查询service
 * @author zx
 *
 */
@Service
@Transactional
public class PrifitShareServiceImpl implements IProfitShareService {
	static Logger logger = Logger.getLogger(PrifitShareServiceImpl.class);

	@Autowired
	ISQLBaseDao sqlBaseDao;

	
	/**
	 * 查询分润
	 */
	@Override
	public List<ProfitShare> queryProfitShare(String sql)
			throws ServiceException {
		List<ProfitShare> backList = new ArrayList<ProfitShare>();

		try {

			List<Object> objList = sqlBaseDao.queryAll(sql);

			for (int i = 0; i < objList.size(); i++) {
				Object[] objs = (Object[]) objList.get(i);
				ProfitShare pro = new ProfitShare();
				pro.setAgentName(Constance.Null2EmptyTrim(objs[0]));
				pro.setMccTypeName(Constance.Null2EmptyTrim(objs[1]));
				pro.setCount1(Constance.Null2EmptyTrim(objs[2]));
				pro.setAmount(Constance.Null2EmptyTrim(objs[3]));
				pro.setFenrunAmt(new BigDecimal(Constance.Null2EmptyTrim(objs[4])));
				pro.setMerfee(Constance.Null2EmptyTrim(objs[5]));

				backList.add(pro);
			}

		} catch (Exception e) {
			logger.debug(e.getMessage());
			throw new ServiceException("查询分润失败,请稍后再试");
		}

		return backList;
	}

}
